<?php
/**
 * Created by PhpStorm.
 * 文件用途描述 :
 * User: 孙洪亮
 * Date: 2018/2/11/011
 * Time: 0:53
 */

namespace app\api\model;


class Theme extends BaseModel
{
    protected $hidden=['from','delete_time','update_time','img_id','banner_id','topic_img_id','head_img_id'];
     public function topicImg(){
         return $this->belongsTo('Image','topic_img_id','id');
     }

     public function headImg(){
         return $this->belongsTo('Image','head_img_id','id');
     }

     public function products(){
         //多对多关系映射 四个参数；Product映射的另一张表名，中间表名，中间表中次映射表ID，中间表中主表ID
         return $this->belongsToMany('Product','theme_product','product_id','theme_id');
     }

     public static function getThemeWithProduicts($id){
         $theme=self::with(['products','topicImg','headImg'])->find($id);
         return $theme;
     }
}